package com.ruoyi.web.controller.comprehensive;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.comprehensive.domain.DustPrevention;
import com.ruoyi.comprehensive.dto.DustPreventionDto;
import com.ruoyi.comprehensive.service.IDustPreventionService;
import com.ruoyi.comprehensive.vo.DustVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 防尘管理Controller
 *
 * @author hcc
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/comprehensive/dust")
public class DustPreventionController extends BaseController
{
    @Autowired
    private IDustPreventionService dustPreventionService;

    /**
     * 查询防尘管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:dust:list')")
    @GetMapping("/list")
    public TableDataInfo list(DustPrevention dustPrevention)
    {
        startPage();
        List<DustPrevention> list = dustPreventionService.selectDustPreventionList(dustPrevention);
        return getDataTable(list);
    }

    /**
     * 导出防尘管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:dust:export')")
    @Log(title = "防尘管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DustPrevention dustPrevention)
    {
        List<DustPrevention> list = dustPreventionService.selectDustPreventionList(dustPrevention);
        ExcelUtil<DustPrevention> util = new ExcelUtil<DustPrevention>(DustPrevention.class);
        util.exportExcel(response, list, "防尘管理数据");
    }

    /**
     * 获取防尘管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:dust:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(dustPreventionService.selectDustPreventionById(id));
    }

    /**
     * 新增防尘管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:dust:add')")
    @Log(title = "防尘管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DustPrevention dustPrevention)
    {
        dustPrevention.setId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(dustPreventionService.insertDustPrevention(dustPrevention));
    }

    /**
     * 修改防尘管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:dust:edit')")
    @Log(title = "防尘管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DustPrevention dustPrevention)
    {
        return toAjax(dustPreventionService.updateDustPrevention(dustPrevention));
    }

    /**
     * 删除防尘管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:dust:remove')")
    @Log(title = "防尘管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dustPreventionService.deleteDustPreventionByIds(ids));
    }
    /**
     * 查询防尘管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:dust:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(DustPrevention dustPrevention) {
        startPage();
        List<DustPreventionDto> list = dustPreventionService.getDustPreventionList(dustPrevention);
        return getDataTable(list);
    }
    /**
     * 获取防尘管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:dust:query')")
    @GetMapping("/getDustPreventionById/{id}")
    public AjaxResult getDustPreventionById(@PathVariable("id") String id) {
        DustPreventionDto dustPreventionDto = dustPreventionService.getDustPreventionById(id);
        return success(dustPreventionDto);
    }
}
